package es.juanc.mail.mio;

import java.io.File;


public class SendMailTest {

	public static void main(String[] args) {
		
		smtpSessionFactory();
	}

	private static void smtpSession() {
		
		SmtpSession smtp = new SmtpSession("smtp.gmail.com", 587, "juancsch@gmail.com","tachatacha");
		
		smtp.setDebug( true );
		smtp.setTls( true );
		
		SmtpMail mail = new SmtpMail("Juan Carlos", "juancsch@gmail.com", "Mail de prueba");
		mail.addToAddress("jc", "juancsch@gmail.com");
		mail.addMessageText("Mailer test. \r\n Simple ASCII text");
		mail.addMessageText("<h1>HOLA</h1>","us-ascii","html");
		mail.addAttachemets("prueba.xls", new File("prueba.xls"));
		
		try {
			smtp.sendMail(mail);
			System.out.println("Mail enviado con exito");
		} catch (Exception e) {
			System.out.println("No se puedo enviar el mail: " + e.getMessage());
			e.printStackTrace();
		}
	}

	private static void smtpSessionFactory() {

		try {
			SmtpConnection smtp = new SmtpConnection("smtp.gmail.com", 587, "juancsch@gmail.com", "tachatacha", true, true);
		
			SmtpMail mail = new SmtpMail("Juan Carlos", "juancsch@gmail.com", "Mail de prueba");
			mail.addToAddress("jc", "juancsch@gmail.com");
			mail.addMessageText("Mailer test. \r\n Simple ASCII text");
			mail.addMessageText("<h1>HOLA</h1>","us-ascii","html");
			mail.addAttachemets("prueba.xls", new File("prueba.xls"));
		
			smtp.sendMail(mail);		
			
			System.out.println("Mail enviado con exito");

			mail = new SmtpMail("FElipe", "juancsch@gmail.com", "Mail de prueba");
			mail.addToAddress("jc", "juancsch@gmail.com");
			mail.addMessageText("Mailer test. \r\n Simple ASCII text");
		
			smtp.sendMail(mail);		
			
			System.out.println("Mail enviado con exito");
			
			smtp.close();
			
		} catch (Exception e) {
			System.out.println("No se puedo enviar el mail: " + e.getMessage());
			e.printStackTrace();
		}
	}
}
